package com.xia.rocket;

import com.xia.domain.OperationLog;
import com.xia.service.OperationLogService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * messageModel=MessageModel.CLUSTERING
 * 监听模式，有消息就会消费
 */
@Service
@RocketMQMessageListener(topic = "com-xia-rocket", consumerGroup = "rocket-mq-consumer", messageModel = MessageModel.CLUSTERING)
public class RocketMQConsumer implements RocketMQListener<OperationLog> {

    @Autowired
    private OperationLogService operationLogService;

    @Override
    public void onMessage(OperationLog log) {
        // 保存日志
        operationLogService.saveLog(log);
        System.out.printf("收到消息: %s\n", log);
    }
}

